import axios from 'axios'
// 请求库配置

var axios_instance = axios.create({
    baseURL: "http://192.168.0.100:11365", // API请求地址
});

/**
 * @author WXS
 * @description 封装了一下默认的方法，把get和post传参的形式封装成一致,允许携带全局变量(AXIOS也支持配置)
 * @param path baseURL后的path例如 /api/getUserInfo
 * @param method String 请求方法（小写）get,post,delete...
 * @param params JSON 请求参数(无参数需填写空JSON) 
 * @param withGlobalParams Boolean 是否携带全局参数(true false) 在方法内globalParams配置 例如携带 userId token...
 */

var customRequest = function (path,method, params, withGlobalParams) {
    var globalParams = {
        token:"token"
    }
    var options = {};
    options.url=path;
    if (method) options.method = method;
    if (withGlobalParams) params = Object.assign(params, globalParams);
    if (method === 'get') options.params = params;
    if (method === 'post') options.data = params;
    return axios_instance(options);
}

export default customRequest;